/*
 * @Author: 张升 1562821455@qq.com
 * @Date: 2023-07-17 10:20:03
 * @LastEditors: 张升 1562821455@qq.com
 * @LastEditTime: 2024-11-04 15:36:25
 * @FilePath: \react-demo\src\views\myhooks\EffectHook.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState, useEffect } from "react";
function Sub () {
    const [count, setCount] = useState(0)
    const [name, setName] = useState('takzhang')
    function touchButton() {
        setCount(count + 1)
    }
    useEffect(() => {
        document.title = count
    }, [count]);
    useEffect(() => {
        const timer = setInterval(() => {
            setCount(count + 1)
        }, 1000)
        return () => {
            clearInterval(timer)
        }
    }, [count])
    return (
        <>
            <button onClick={touchButton}>{count}</button>
            <button onClick={() => {
                if (name === 'takzhang') {
                    setName('jack')
                } else {
                    setName('takzhang')
                }
            }}>{name}</button>
        </>
    )
}
class App extends React.Component {
    render() {
        return (
            <div>
                <Sub></Sub>
            </div>
        )
    }
}
export default App